# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import pymongo



class MyspiderPipeline:
    def __init__(self):

        host = '127.0.0.1'
        port = 27017
        dbName = 'spider_month_exame'
        client = pymongo.MongoClient(host=host, port=port)
        tdb = client[dbName]
        self.post = tdb['what_buy']

    def process_item(self, item, spider):
        article = dict(item)
        self.post.insert(article)
        return item
